package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.GoodsTypeVo;
import com.atguigu.jxc.service.GoodsTypeService;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.HashSet;


@RestController
@RequestMapping("goodsType")
@Slf4j
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    /**
     * 查询商品分类
     * @return
     */
    @PostMapping("/loadGoodsType")
    public String loadGoodsType(){
        GoodsTypeVo goodsTypeVo = goodsTypeService.selectAll();
        HashSet<Object> set = new HashSet<>();
        set.add(goodsTypeVo);
        Gson gson = new Gson();
        String result = gson.toJson(set);
        return result;
    }


    @PostMapping("/save")
    public ServiceVO save(String  goodsTypeName,Integer  pId){
        goodsTypeService.save(goodsTypeName,pId);
        return new ServiceVO(100,"请求成功");
    }

    @PostMapping("/delete")
    public ServiceVO delete(Integer  goodsTypeId){
        log.info("------开始删除---------");
        goodsTypeService.delete(goodsTypeId);
        return new ServiceVO(100,"请求成功");
    }





}
